/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* reverseList(ListNode* head) {
        if(head==nullptr)
            return nullptr;

        ListNode dummy(0);
        ListNode* ret = &dummy;
        ListNode* rret = ret;
        vector<int> tmp={};
        ListNode *temp=head;
        while(temp !=nullptr){
            tmp.push_back(temp->val);
            temp=temp->next;
        }
        for(int i=tmp.size()-1;i>=0;--i){
       
            ret->next=new ListNode(tmp[i]);; 
            ret=ret->next;
        }
        return dummy.next;
    }
};